package jfuzzyprincepless.zarchive.variables;

import java.util.*;

public class FuzzySet<E> implements IFuzzySet<E> {
	@SuppressWarnings("unchecked")
	public static final IFuzzySet EMPTY_SET = new FuzzySet();

	private static final double IS_NOT_MEMBER_VALUE = 0.0;

	private Map<E, Double> elements2membership =
		new LinkedHashMap<E, Double>();
	private double isNotMemberValue = IS_NOT_MEMBER_VALUE;

	@Override
	public Set<E> getElements() {
		return elements2membership.keySet();
	}

	@Override
	public double getMembershipDegree(E elem) {
		if (elements2membership.containsKey(elem)) {
			return elements2membership.get(elem);
		} else {
			return isNotMemberValue;
		}
	}

	@Override
	public void add(E elem, double membershipDegree) {
		elements2membership.put(elem, membershipDegree);
	}

	@SuppressWarnings("unchecked")
	public static <T> IFuzzySet<T> emptySet() {
		return EMPTY_SET;
	}
}
